<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of datecategory
 *
 * @author chaporgin_a
 */
class VA_ContentModelDateCategory extends ContentModelCategory {
    /**
     * timestamp, from which date to select articles, inclusive
     * @var int 
     */
    private $from = null;
    /**
     * timestamp, till which date to select articles, not inclusive
     * @var int
     */
    private $till = null;
    /**
     * 
     * @param int $from timestamp, from which date to select articles, inclusive
     * @param int $till timestamp, till which date to select articles, not inclusive
     */
    public function __construct($from = null, $till = null) {
        if(null===$from) $from = strtotime(date('Y-m-01'));
        if(null===$till) $till = strtotime('+1 month', $from);
        $this->from = $from;
        $this->till = $till;
        parent::__construct();
    }
    public function _buildContentWhere($state = 1) {
        $where = parent::_buildContentWhere($state);
        $q = " AND (a.created_at BETWEEN '%s' AND '%s')";
        $q = sprintf($q
                , date('Y-m-d', $this->from)
                , date('Y-m-d', $this->till)
                );
        $where .= $q;
        return $where;
    }
}

